package org.gwt.grin.rebind.features;

import java.util.Formatter;

import org.gwt.grin.client.features.Box;
import org.gwt.grin.client.util.BgImage;
import org.gwt.grin.client.util.Color;
import org.gwt.grin.rebind.SEFeature;
import org.gwt.grin.rebind.ShowBuilder;

import com.google.gwt.uibinder.rebind.IndentedWriter;

public class SEBox extends SEFeature {

	protected final int x;
	protected final int y;
	protected final int width;
	protected final int height;
	protected final int outlineWidth;
	protected final Color outlineColor;
	protected final Color fillColor;
	protected final BgImage bgImage;
	protected SEScalingModel scalingModel;

	public SEBox(String name, int x, int y, int width, int height,
			int outlineWidth, Color outlineColor, Color fillColor,
			BgImage bgImage) {
		super(name);
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.outlineWidth = outlineWidth;
		this.outlineColor = outlineColor;
		this.fillColor = fillColor;
		this.bgImage = bgImage;
	}

	protected String getClassName() {
		return Box.class.getName();
	}

	public void setup(SEScalingModel scalingModel) {
		this.scalingModel = scalingModel;
	}

	public String write(ShowBuilder builder) {
		String cn = getClassName();
		Formatter formatter = new Formatter();
		formatter.format("new %s(\"%s\")", cn, name);
		return formatter.toString();
	}

	public void setup(IndentedWriter w, ShowBuilder builder) {
		String vn = getVN(builder);
		w.write("%s.setup(%d, %d, %d, %d, %d, %s, %s, %s, %s);", vn, x, y,
				width, height, outlineWidth, makeColor(outlineColor),
				makeColor(fillColor), makeBgImage(bgImage),
				makeScalingModel(builder));
	}

	protected String makeScalingModel(ShowBuilder builder) {
		return scalingModel == null ? "null" : scalingModel.getVN(builder);
	}

}
